<?php
/*// ----------------------------------------------------注册树模式----------------------------------------------
class  Contair{
    private  $binds=[];
    public  function register($abstract,$concrate){
        $this->binds[$abstract]=$concrate;
    }
    public  function  make($abstract){
        $object=$this->binds[$abstract];
        if($object instanceof \Closure){
            return $object();
        }
        if(!is_object($object)){
            $object = new $object();
        }
        return $object;
    }
    public  function  delete($abstract){
        unset($this->binds[$abstract]);
    }
}
class  A {
    public  function  boot(){
        echo  "我是A类的boot方法".PHP_EOL;
    }
}
$contair = new Contair();
$contair->register('A',new A());
$contair->make('A')->boot();*/

// ----------------------------------------------------适配器模式----------------------------------------------
/*interface I{
    public  function boot();
}
class A implements  I {
    public function str()
    {
        // TODO: Implement str() method.
    }

    public function m($a, array $b, array $c = array())
    {
        // TODO: Implement m() method.
    }

    public function boot()
    {
        return json_encode(["name"=>"zhangsan","mobile"=>'1222222']);
    }
}
class B implements  I {
    public function str()
    {
        // TODO: Implement str() method.
    }

    public function m($a, array $b, array $c = array())
    {
        // TODO: Implement m() method.
    }

    public function boot()
    {
        return serialize(["name"=>"zhangsan","mobile"=>'1222222']);
    }
}
interface  I_Adator{
    public  function boor(I $i);
}
class Adator implements  I_Adator{

    public function boor(I $i)
    {
       if(!is_null($string=json_decode($i->boot()))){
           return serialize($string);
       }else{
           $string = unserialize($i->boot());
           return json_encode($string);
       }
    }
}
$adator = new Adator();
var_dump($adator->boor(new A()));
var_dump($adator->boor(new B()));*/


// ----------------------------------------------------Pipeline模式----------------------------------------------

// ----------------------------------------------------代理模式----------------------------------------------
interface I{
    public function boot();
    public  function handle();
}
class A implements I{

    public function str()
    {
        // TODO: Implement str() method.
    }

    public function m($a, array $b, array $c = array())
    {
        // TODO: Implement m() method.
    }

    public function boot()
    {
       echo "这是A类的boot方法".PHP_EOL;
    }

    public function handle()
    {
        echo "这是A类的handle方法".PHP_EOL;
    }
}

class Proxy implements I{
    protected  $A;
    public function __construct(I $i)
    {
        $this->A=$i;
    }

    public function str()
    {
        // TODO: Implement str() method.
    }

    public function m($a, array $b, array $c = array())
    {
        // TODO: Implement m() method.
    }

    public function boot()
    {
     $this->A->boot();
    }

    public function handle()
    {
      $this->A->handle();
    }
}
$proxy= new Proxy(new A());
$proxy->boot();
$proxy->handle();